<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        a{
            cursor: pointer;
        }
    </style>
</head>
<body>
 姓名：<input type="text" value="" id="name">
 年龄：<input type="text" value="" id="age">
 <button id="addBtn">添加</button>
  <table border="1" style="border-collapse: collapse">
      <thead>
      <th>编号</th>
      <th>名字</th>
      <th>年龄</th>
      <th>操作</th>
      </thead>
      <tbody>
      <tr>
          <td>1</td>
          <td>A</td>
          <td>10</td>
          <td><a>删除</a></td>
      </tr>
      <tr>
          <td>2</td>
          <td>B</td>
          <td>11</td>
          <td><a>删除</a></td>
      </tr>
      <tr>
          <td>3</td>
          <td>C</td>
          <td>12</td>
          <td><a>删除</a></td>
      </tr>
      <tr>
          <td>4</td>
          <td>D</td>
          <td>13</td>
          <td><a>删除</a></td>
      </tr>
      <tr>
          <td>1</td>
          <td>A</td>
          <td>10</td>
          <td><a>删除</a></td>
      </tr>

      </tbody>
  </table>
 <script type="text/javascript">
     var oName = document.getElementById('name');
     var oAge = document.getElementById('age');
     var addBtn = document.getElementById('addBtn');
     var oTable = document.getElementsByTagName('table')[0];
     var id = 2;
     var aA = document.getElementsByTagName('a');

     function createElement() {
         var oTr = document.createElement('tr');

         var oTd = document.createElement('td');
         oTd.innerHTML = id++;
         oTr.appendChild(oTd);//id

         var oTd = document.createElement('td');
         oTd.innerHTML = oName['value'];
         oTr.appendChild(oTd);//name

         var oTd = document.createElement('td');
         oTd.innerHTML = oAge['value'];
         oTr.appendChild(oTd);//age

         var oTd = document.createElement('td');
         oTd.innerHTML = "<a >删除</a>";
         oTr.appendChild(oTd);//age

         oTable.tBodies[0].appendChild(oTr);
         for(var i = 0;i<aA.length;i++){
             alert("123");
             aA[i].onclick = function () {
                 oTable.tBodies[0].removeChild(this.parentNode.parentNode);
             }
         }

     }

     addBtn.onclick = function () {
         createElement();
     };





 </script>
</body>
</html>